<!--
- File:    积分收支页
-->
<template>
  <div class="Web_Box">
    <div class="integrat f-cb"><span>当前积分 {{currentIntegral}}</span><a v-if="false" @click="gotoSpread" class="more">推荐用户购买</a></div>
    <div class="inter_tab" v-infinite-scroll="loadMoreIntegral"
      infinite-scroll-disabled="false"
      infinite-scroll-distance="0"
      infinite-scroll-immediate-check="false">
      <table width="100%" border="0">
        <tr>
          <th align="left">时间</th>
          <th align="center">收支类型</th>
          <th align="right">积分</th>
        </tr>
        <tr v-for="item in integral.data">
          <td>{{item.addtime | timestampToDate('yyyy-MM-dd')}} <p class="f12">{{item.addtime | timestampToDate('hh:mm:ss')}}</p></td>
          <td align="center">{{integralStatus(item.style).txt}}</td>
          <td>
            <a class="fr">
            <span class="cr_45a73a vm" v-if="integralStatus(item.style).trend == '+'">+{{item.integral_value}}</span>
            <span class="cr_f60202 vm" v-if="integralStatus(item.style).trend == '-'">-{{item.integral_value}}</span>
            <!--<span class="vm pl20" @click="gotoOrderDetail(item)">查看</span>-->
            </a>
          </td>
        </tr>
      </table>
    </div>
    <empty-data :show="integral.allLoaded && integral.data.length <= 0" style="margin-top: 1.5rem"></empty-data>
    <footer-tab></footer-tab>
  </div>
</template>

<script>

  export default{
    data() {
      return {
        integral: {requested: false, loading: false, allLoaded: false, page: 1, pageSize: 10, data: []}
      }
    },
    components: {},
    created() {
      this.initIntegralList()
      this.getIntegralList(this.integral.page, this.integral.pageSize)
    },
    methods: {
      gotoSpread() {
        this.$router.push({name: 'member-spread'})
      },
      gotoOrderDetail(order) {
        let self = 'true'
        if (order.style == 2 || order.style == 8) {
          self = 'false'
        }
        this.$router.push({name: 'order-detail', params: {id: order.order_id}, query: {self: self}})
      },
      initIntegralList() {
        this.integral.requested = false
        this.integral.loading = false
        this.integral.allLoaded = false
        this.integral.page = 1
        this.integral.pageSize = 10
        this.integral.data = []
        this.currentIntegral = 0
      },
      getIntegralList(page, pageSize) {
        this.integral.loading = true
        this.$request.getIntegralList(page, pageSize).then(data => {
          this.currentIntegral = data.member_integral
          if (data.integral_list.length < this.integral.pageSize) {
            this.integral.allLoaded = true
          }
          this.integral.data = [...this.integral.data, ...data.integral_list]
        }).finally(() => {
          this.integral.requested = true
          this.integral.loading = false
        })
      },
      loadMoreIntegral() {
        if (this.integral.loading || this.integral.allLoaded) { // 正在加载 或 已取得全部数据
          return
        }
        setTimeout(() => {
          this.getIntegralList(++this.integral.page, this.integral.pageSize)
        }, 500)
      },
      integralStatus(value) {
        let info = {txt: '', trend: ''}
        switch (value) {
          case '1':
            info = {txt: '购买生成积分', trend: '+'}
            break
          case '2':
            info = {txt: '下级购买生成积分', trend: '+'}
            break
          case '3':
            info = {txt: '购买使用积分', trend: '-'}
            break
          case '4':
            info = {txt: '取消订单返回积分', trend: '+'}
            break
          case '5':
            info = {txt: '退款返回积分', trend: '+'}
            break
          case '7':
            info = {txt: '退货扣除赠送的积分', trend: '-'}
            break
          case '8':
            info = {txt: '下级退货扣除积分', trend: '-'}
            break
          case '9':
            info = {txt: '退货被拒返回积分', trend: '+'}
            break
          case '10':
            info = {txt: '下级退货被拒返回积分', trend: '+'}
            break
          case '11':
            info = {txt: '下级退货扣除积分', trend: '-'}
            break
          case '12':
            info = {txt: '取消退货返回积分', trend: '+'}
            break
          case '13':
            info = {txt: '下级取消退货返回积分', trend: '+'}
            break
          case '14':
            info = {txt: '退货返回使用的积分', trend: '+'}
            break
          case '15':
            info = {txt: '租花使用积分', trend: '-'}
            break
          case '16':
            info = {txt: '取消租花定单返回积分', trend: '+'}
            break
          case '17':
            info = {txt: '租花获得积分', trend: '+'}
            break
          case '100':
            info = {txt: '发布遇见获得积分', trend: '+'}
            break
          case '101':
            info = {txt: '发布文章获得积分', trend: '+'}
            break
          case '102':
            info = {txt: '被推荐精品文章获得积分', trend: '+'}
            break
          case '103':
            info = {txt: '发布成长日志获得积分', trend: '+'}
            break
          case '104':
            info = {txt: '新建花园获得积分', trend: '+'}
            break
          case '105':
            info = {txt: '新建共享花园获得积分', trend: '+'}
            break
          case '106':
            info = {txt: '分享朋友获得积分', trend: '+'}
            break
          case '107':
            info = {txt: '分享朋友圈获得积分', trend: '+'}
            break
          case '108':
            info = {txt: '租花获得积分', trend: '+'}
            break
        }
        return info
      }
    }
  }
</script>
